package common;

import java.io.Serializable;
import java.net.URI;
import java.util.ArrayList;

public class SubscriptionInfo implements Serializable {

	public enum Action {
		ADD, REMOVE;
	}

	private static final long serialVersionUID = 1L;
	public Action action;

	// Set to true only when the subscribe message is a Action.REMOVE one and is
	// from a locally attached client stopping.
	public boolean clientStopping = false;
	public URI source;
	public URI subscriber;
	public String topic;
	public ArrayList<URI> visitedBrokers = new ArrayList<URI>();

	public SubscriptionInfo(URI source, URI subscriber, String topic,
			Action action) {
		super();
		this.source = source;
		this.subscriber = subscriber;
		this.topic = topic;
		this.action = action;
	}

	// If clientStopping is true, action have to be REMOVE.
	public SubscriptionInfo(URI source, URI subscriber, String topic,
			Action action, boolean clientStopping) {
		super();
		this.source = source;
		this.subscriber = subscriber;
		this.topic = topic;
		this.action = action;
		this.clientStopping = clientStopping;
	}

	public void addVisited(URI uri) {
		this.visitedBrokers.add(uri);
	}

	public boolean isVisited(URI uri) {
		return this.visitedBrokers.contains(uri);
	}
}
